import {CpuGetApi, RemoveApi} from "@/common/customs/overview";

export const addTableConfig = (MyTable, MyForm, Self) => {
  MyTable.columns = [
    {
      title: "序号",
      key: "id",
      width: 100,
      slot: "c-index",
    },
    {
      title: "名称",
      key: "name",
    },
    {
      title: "说明",
      key: "sm",
    },
    {
      title: "pid",
      key: "pid",
      width: 100,
    },
    {
      title: "占比",
      key: "zb",
      width: 100,
    },
    {
      title: "操作",
      // key: "syms",
      // width: 80,
      slot: "c-action",
      items: [
        {
          name: "修改",
          color: "#b7ffff",
          callback: async (record) => {
            MyForm.formDatas = {};
            MyForm.formDatas = record;
            MyForm.show = true;
          }
        },
        {
          name: "删除",
          color: "red",
          callback: async (record) => {
            const api = new RemoveApi();
            api.query(["id", record.id]);
            api.hint("删除");
            await api.send();
            const data = await api.getDatas();
            MyTable.getDatas();
          }
        },
      ]
    },
  ];
  MyTable.overWidth = 800;
  MyTable.pageSize = 12;
  MyTable.getDatas = async () => {
    try {
      const api = new CpuGetApi()
        .params({
          page: MyTable.pageConfig.current,
          page_size: MyTable.pageConfig.pageSize,
        });
      await api.send();
      const {data} = await api.getDatas();
      await MyTable.setDatas(data.data, data.total);
    } catch (err) {
      console.log(err);
    }
  };
  MyTable.onSearch = (val) => {
    MyTable.getDatas(val);
  };
};
